﻿using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Xml.Serialization;

using G.Model.Converters;

namespace G.Model
{
    [DataContract]
    public class GameTaskDef : HasGameSpaceDef, HasName
    {
        private GameSpaceDef _GameDef;
        
        [DataMember(Name="Name")]
        private string _Name;

        public GameTaskDef() : this(null) 
        { 
            _Name = "Task";
        }
        
        public GameTaskDef(GameSpaceDef pGameDef)
        {
            _GameDef = pGameDef;
            _Name = "Task";
        }
       
        [IgnoreDataMember]
        public string Name
        {
            get { return _Name; }
            set 
            {
                if (_GameDef != null)
                {
                    _GameDef.GameTaskDefs.ChangeKey(this, value);
                }
                _Name = value; 
                if (_GameDef != null)
                {
                    _GameDef.GameTaskDefs.FireChangedEvent();
                }
            }
        }

        [Browsable(false), IgnoreDataMember]
        public GameSpaceDef GameDef
        {
            get { return _GameDef; }
            set { _GameDef = value; }
        }
        
        public override string ToString()
        {
            return Name;
        }
    }
}
